package com.magicalcoder.youyamvc.web.controller.admin.common;

import com.magicalcoder.youyamvc.core.cache.common.CacheUtil;
import com.magicalcoder.youyamvc.core.spring.admin.AdminLoginController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by hedongyu on 2017/2/8.
 * 799374340@qq.com
 * 通用工具类
 */
@Controller
@RequestMapping(value="/admin/util")
public class CommonUtilController extends AdminLoginController {

    @RequestMapping(value = "/set_cache/{cacheKey}",method = RequestMethod.GET)
    public void setCache(@PathVariable String cacheKey,
                         @RequestParam String cacheValue,
                         HttpServletRequest request, HttpServletResponse response)
    {
        CacheUtil.resetCache(cacheKey,300,cacheValue);
        toWebSuccessJson(response);
    }
    @RequestMapping(value = "/get_cache/{cacheKey}",method = RequestMethod.GET)
    public void getCache(@PathVariable String cacheKey,
                         HttpServletRequest request, HttpServletResponse response)
    {
        String cacheValue = CacheUtil.get(cacheKey);
        toWebSuccessJson(response, cacheValue,false);
    }

}
